package com.tsing.wms.controller;


import com.tsing.wms.annotation.PassToken;
import com.tsing.wms.service.IOutInRecordService;
import com.tsing.wms.util.ResultUtil;
import com.tsing.wms.valid.AddGroup;
import com.tsing.wms.vo.PageResultVO;
import com.tsing.wms.vo.ResultData;
import com.tsing.wms.vo.req.ExportRecordReqVO;
import com.tsing.wms.vo.req.IdReqVO;
import com.tsing.wms.vo.req.RecordPageReqVO;
import com.tsing.wms.vo.req.RecordReqVO;
import com.tsing.wms.vo.resp.IdAndNameRespVO;
import com.tsing.wms.vo.resp.RecordRespVO;
import com.tsing.wms.vo.resp.StockListRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 出入库记录表 前端控制器
 * </p>
 *
 * @author TheTsing
 * @since 2022-04-13
 */
@Api(tags = "出入库管理")
@RestController
@RequestMapping("/outRecord")
public class OutInRecordController {

    @Autowired
    private IOutInRecordService outInRecordService;

    @GetMapping("/storehouseList")
    @ApiOperation(value = "仓库列表")
    public ResultData<List<IdAndNameRespVO>> storehouseList() {
        return ResultUtil.success(outInRecordService.storehouseList());
    }

    @GetMapping("/stockList")
    @ApiOperation(value = "根据仓库id获取库存列表")
    public ResultData<List<StockListRespVO>> stockList(IdReqVO reqVO) {
        return ResultUtil.success(outInRecordService.stockList(reqVO));
    }

    @PostMapping("/addRecord")
    @ApiOperation(value = "新增出入库")
    public ResultData addRecord(@Validated({AddGroup.class}) @RequestBody RecordReqVO reqVO, HttpServletRequest request) {
        outInRecordService.addRecord(reqVO, request);
        return ResultUtil.success();
    }

    @GetMapping("/getRecord")
    @ApiOperation(value = "查询出入库详情")
    public ResultData<RecordRespVO> getRecord(@Validated IdReqVO reqVO) {
        return ResultUtil.success(outInRecordService.getRecord(reqVO));
    }

    @GetMapping("/recordPage")
    @ApiOperation(value = "出入库分页")
    public ResultData<PageResultVO<RecordRespVO>> recordPage(@Validated RecordPageReqVO reqVO) {
        return ResultUtil.success(outInRecordService.recordPage(reqVO));
    }

    @PassToken
    @GetMapping("/exportRecord")
    @ApiOperation(value = "导出记录表")
    public void exportRecord(@Validated ExportRecordReqVO reqVO, HttpServletRequest request, HttpServletResponse response) {
        outInRecordService.exportRecord(reqVO, request, response);
    }

}
